﻿using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wimm.Common.Entities.Utils;
using Wimm.Common.Interfaces.Services;

namespace Wimm.Common.Entities
{
    public class Income:Transaction
    {
        public Income()
        {
            //For SQL Light usage only
        }
        public Income(DateTime time, int amount, int userId, int sourceId, String comment)
            : base(amount, time, userId)
        {
            this.IncomeSourceId = sourceId;
            this.Comment = comment;
        }

        public Income(long time, int amount, int userId, int sourceId, String comment)
            : base(amount, time, userId)
        {
            this.IncomeSourceId = sourceId;
            this.Comment = comment;
        }

        public Decimal AmountIncome
        {
            get { return (Decimal)this.Amount / 100.00M; }
        }

        public int IncomeSourceId { get; protected set; }

        public String Comment { get; set; }
    }

    public class IncomeIcon : Income
    {
        public IncomeIcon(Income income, Icon icon, String sourceName, IIncomeService incomeService)
        {
            this.Id = income.Id;
            this.Amount = income.Amount;
            this.IncomeSourceId = income.IncomeSourceId;
            this.Time = income.Time;
            this.UserId = income.UserId;
            this.Comment = income.Comment;
            this.Icon = icon;
            this.CategoryName = sourceName;
            this.IncomeService = incomeService;
            this.Command = new RelayCommand(SaveCommand);
        }

        private async void SaveCommand()
        {
            var income = new Income(this.Time, this.Amount, this.UserId, this.IncomeSourceId, this.Comment);
            income.SetId(this.Id);
            await IncomeService.EditIncome(income);
            Messenger.Default.Send(new IncomeUpdateGridItemMessenge(this.Id, this.Comment));
        }

        private IIncomeService IncomeService;
        public RelayCommand Command { get; protected set; }
        public String CategoryName { get; protected set; }
        public Icon Icon { get; protected set; }
    }
}
